<?php
namespace app\zhihui\controller;

use think\Db;
use think\Controller;
/**
 * 智慧寺院登录控制器
 * Class Login
 * @package app\index\controller
 */
class Login extends Controller
{
    /**
     * [bindtel 绑定手机]
     * @param
     * @author [C。]
     * @return json
     */
    public function bindtel()
    {
        $param = input('param.');
        $map = [];
        $map['tel'] = $param['tel'];
        $map['code'] = $param['code'];
        $map1 = [];
        $map1['tel'] = $param['tel'];

        $mem = Db::name('member')->where($map1)->find();
        if(!empty($mem)){
            return admin_json('-4','手机号已被绑定！');
        }
        $result = Db::name('vercode')->where($map)->find();
        if(!empty($result)) {
            if ($result['status'] == 2) {
                return admin_json('-3', '验证码已使用');
            }
            if (time() - $result['addtime'] > config('home.code_expiration_time')) {
                return admin_json('-2', '验证码已过期');
            }
            Db::name('vercode')->where($map)->update(['status' => 2]);
        }else{
            return admin_json('-1','手机号或验证码错误');
        }
        $member = Db::name('member')->field('id')->where(['token'=>$param['token']])->find();
        Db::name('member')->where(['id'=>$member['id']])->update(['tel'=>$param['tel']]);

        return admin_json('1','绑定成功');

    }
}